package com.example.xadmin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.xadmin.dao.SysUserMapper;
import com.example.xadmin.pojo.SysRoleUser;
import com.example.xadmin.pojo.SysUser;
import com.example.xadmin.service.SysRoleUserService;
import com.example.xadmin.service.SysUserService;
import com.example.xadmin.util.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Administrator
 * @since 2020-04-05
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Autowired
    private SysRoleUserService sysRoleUserService;

    @Override
    public void saveEntity(SysUser sysUser,Integer roleId) throws Exception {
        sysUser.setPassword(Md5Util.encode(sysUser.getPassword()));
        sysUser.setStatus(true);

        this.save(sysUser);

        if(roleId!=null){
            SysRoleUser entity = new SysRoleUser();
            entity.setRoleId(roleId);
            entity.setUserId(sysUser.getId());
            sysRoleUserService.save(entity);
        }

    }
}
